/**
 *  我是学生-我的课程
 */
$(function(){
	//鼠标经过效果
	$("ul.ul_wdkcPic li").hover(
		function(){
			$(this).find("div.oPic_wdkc").addClass('oPic_wdkc_hover');
		},
		function(){
			$(this).find("div.oPic_wdkc").removeClass('oPic_wdkc_hover');
		}
	);
	//开通短信通知
	$("#message_remind").click(
		function(){
			var Box = $.ckAjaxBoxy({
				url : '/?mod=student&act=course&do=remind',
				title : "短信提醒",
				width : 354,
				height : 194,
				callback:function(){
					$("#fe_dialogBox").find("a.cancel").unbind().bind('click', function(){
						Box.cancel();
					});
				}
			});
		}
	);
	
	$("#ul_wdkcPic div.item34").hover(
		function(){
			$(this).addClass('item34_select');
		},
		function(){	
			$(this).removeClass('item34_select');
		}
	);
});
function del(CourseID, SID, StudentUID, StudyStatus){
	$.ckConfirm({
		message : "您确定要将该课程放入历史课程吗？",
		ok :function(){
			var postStr = [
		       'courseid='+encodeURIComponent(CourseID),
		       'sid='+encodeURIComponent(SID),
		       'studentid='+encodeURIComponent(StudentUID),
		       'studystatus='+encodeURIComponent(StudyStatus),
		     ].join('&');
		 	$.ajax({
		 		url : "/?mod=student&act=course&do=delete",
		 		async : false,
		 		type : "post",
		 		data : postStr,
		 		dataType : "json",
		 		success : function(rs){
		 			if(rs.code == 0){
		 				$("#Course_"+rs.data.CourseID).remove();
		 				window.location.reload();
		 			}else{
		     			$("#Course_"+rs.data).remove();
		     			window.location.reload();
		 			}
					
		 		}
		 	});
		}
	});	
}
function delSaleStatus (StudyStatus){
	if(StudyStatus==2){	
		$.ckConfirm({
			message : "你确定将所有已过期课程移至历史课程？",
			ok :function(){
				var postStr = [
	               'studystatus='+encodeURIComponent(StudyStatus),
	             ];
	         	$.ajax({
	         		url : "/?mod=student&act=course&do=deleteSaleStatus",
	         		async : false,
	         		type : "post",
	         		data : postStr,
	         		dataType : "json",
	         		success : function(rs){
						window.location.reload(); 
	         		}
	         	});
			}
		});
	} else {
		$.ckAlert({
			message : "课程中暂无已过期课程！"
		});		
	}
}

function recoverCourse(sid, courseid) {
	var tipsBoxy = null;
	$.ajax({
		url:'/?mod=student&act=course&do=recover&sid='+sid+'&courseid='+courseid+'&rand='+Math.random(),
		type:'get',
		dataType:'json',
		beforeSend:function() {
			tipsBoxy = $.ckTipsBoxy({type:"loading",message:"课程恢复中...", mask:true});
		},
		success:function(ret) {
			if (ret.code == 0) {
				if($('#recyclelist li').size() == 1){
 					if($('.ck_page a.prev').attr("href") != undefined){
 						window.location.href=$('.ck_page a.prev').attr("href");
 					}else{
 						window.location.reload();
 					}
 				}else{
 					window.location.reload();
 				}
			} else {
				tipsBoxy.cancel();
				$.ckAlert({message:ret.data});
			}
		}
	});
}

//我的课程
var MyChuanke = (function(my) {

	my.announcement = function() {
		$('#announcement_close').click(function(event) {
			$.ajax({
				url   : "/?mod=student&act=announcement&do=oper&op=close&_t=" + _t,
				async : false,
				type  : "post",
				dataType : "json",
				success  : function() {
					$('#announcement_open').css({'background-position':'0 -1300px'}).show();
					$('.pageContent .notice-box').stop().animate({
						'height'        : 0,
						'margin-bottom' : 0
					}, 1000, '', function() {
						$('.pageContent .notice-box').hide();
						//飞行轨迹
						$('.announcement_fly').show();
						moveAnnouncement($('.announcement_fly'));
					});
				}
			});
		});
		$('#announcement_open').click(function() {
			$.ajax({
				url   : "/?mod=student&act=announcement&do=oper&op=open&_t=" + _t,
				async : false,
				type  : "post",
				dataType : "json",
				success  : function() {
					$('#announcement_open').stop().animate({'backgroundPosition':'0 -1306px'}, 100).hide();
					$('.pageContent .notice-box').animate({
						'height'        : 34,
						'margin-bottom' : 20
					}, 1000, '', function() {
						$('.pageContent .notice-box').show();
					});
				}
			});
		});
	};

	my.init = function() {
		this.announcement();
	}

	function moveAnnouncement(start) {
		start.css({ "left": "5px", "top": "7px" }).show();
		//start.parent().append(start.clone());
		start.animate({ "left": "-40px", "top": "11px" }, 1000, function () {
			$('#announcement_open').css({'background-position':'0 -1323px'});
			$(this).hide();
		});
	}

	return my;

})(window.MyChuanke || {});